***Out of Sight, Out of Mind?***
***Tables in Revised version, main text***
***Last update: 07.05.2021 GC

clear
clear mata
clear matrix
cap log close
set more off

set matsize 10000
set maxvar 30000
set max_memory 32g, permanently

log using "replication_tables_main.log", replace

*load data
use "final_data.dta", clear

summ
tab electionType

*labels for tables
la var Dwalk_3 "$\Delta$ Walking time"
la var Dwalk_5 "$\Delta$ Walking time"

la var Dwalk_center_3 "$\Delta$ Walking time (centroid)"
la var Dwalk_center_5 "$\Delta$ Walking time (centroid)"

la var Dakp_3 "$\Delta$ AKP vote share"
la var Dakp_5 "$\Delta$ AKP vote share"

la var Dpop1000_asm_dr_3 "$\Delta$ Congestion"
la var Dpop1000_asm_dr_5 "$\Delta$ Congestion"

la var lograyic "PropertyValue2009"


* Table 1: Descriptives, by year

replace uni_mez_sh=uni_mez_sh*100

global vars="akp_pc akp_margin time_walk_min pop_asm_dr turnout voters_registered population uni_mez_sh privatehospital publichospital odr ydr medrayic09"

mat M=J(14, 2, .)

local k=1	
foreach var in $vars {
		summ `var' if id_election==2
		mat M[`k',1] = round(r(mean), .001)
		summ `var' if id_election==4
		mat M[`k',2] = round(r(mean), .001)
		local k=`k'+1
		}
sum school_id_cluster if id_election==2
mat M[14,1] = round(r(N), 1)
sum school_id_cluster if id_election==4
mat M[14,2] = round(r(N), 1)

mat coln M = "2009 PC" "2011" 
mat rown M = "AKP Vote Share" "AKP Vote Margin" "Walking minutes" "Persons/doctor" "Turnout" "Voters Registered" "Neighborhood Population" "\% University Graduates" "Private Hospitals" "Public Hospital (0,1)" "Old Dependency Ratio" "Young Dependency Ratio" "Median Land Value, 2009" "Observations"
mat list M,	format(%3.2f)

esttab matrix(M, fmt(%3.2f)) using "$output/table1.tex", replace style(tex) mlabels(,none) alignment(cccc) compress booktabs gaps noeqlines

******


* Table 2: Dwalk, Main result
	
*elec_combo=3: 2009belmeclis,2011,2014belmeclis,2015june
global controls_walk="Dpopulation_3 Duniversity_3 Dhospital_pri_3 Dhospital_pub_3 Dodr_3 Dydr_3 medrayic09"
global controls_walk3="akp_pc_2009_belmeclis time_walk_min_2009_belmeclis Dpopulation_3 Duniversity_3 Dhospital_pri_3 Dhospital_pub_3 Dodr_3 Dydr_3 medrayic09"

reg Dakp_3 Dwalk_3 $controls_walk  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table2.tex", keep(Dwalk_3) bdec(3) nocons label tex(frag) replace ///
	addtext(Covariates, YES, Baseline Controls, NO, Cluster, Poll Station, Elec2009, MC) nonotes

reg Dakp_3 Dwalk_3 $controls_walk  if year<2014, cluster(rn)
outreg2 using "$output/table2.tex", keep(Dwalk_3) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, NO, Cluster, Neighborhood, Elec2009, MC) nonotes

reg Dakp_3 Dwalk_3 $controls_walk3  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table2.tex", keep(Dwalk_3) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, YES, Cluster, Poll Station, Elec2009, MC) nonotes

reg Dakp_3 Dwalk_center_3 $controls_walk  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table2.tex", keep(Dwalk_center_3) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, NO, Cluster, Poll Station, Elec2009, MC) nonotes
	
*elec_combo=5: 2009ilgenel,2011,2014belmeclis,2015june
global controls_walk="Dpopulation_5 Duniversity_5 Dhospital_pri_5 Dhospital_pub_5 Dodr_5 Dydr_5 medrayic09"
global controls_walk3="akp_pc_2009_ilgenel time_walk_min_2009_ilgenel Dpopulation_5 Duniversity_5 Dhospital_pri_5 Dhospital_pub_5 Dodr_5 Dydr_5 medrayic09"

reg Dakp_5 Dwalk_5 $controls_walk  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table2.tex", keep(Dwalk_5) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, NO, Cluster, Poll Station, Elec2009, PC) nonotes

reg Dakp_5 Dwalk_5 $controls_walk  if year<2014, cluster(rn)
outreg2 using "$output/table2.tex", keep(Dwalk_5) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, NO, Cluster, Neighborhood, Elec2009, PC) nonotes
	
reg Dakp_5 Dwalk_5 $controls_walk3  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table2.tex", keep(Dwalk_5) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, YES, Cluster, Poll Station, Elec2009, PC) nonotes
	
reg Dakp_5 Dwalk_center_5 $controls_walk  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table2.tex", keep(Dwalk_center_5) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, NO, Cluster, Poll Station, Elec2009, PC) nonotes

*Conley-Spatial adjustment

acreg Dakp_5 Dwalk_5 $controls_walk if year<2014, spatial latitude(from_lat) longitude(from_lng) dist(1)
	
******
	
* Table 3: outcome: Dakpmargin and Dturnout

*elec_combo=3: 2009belmeclis,2011,2014belmeclis,2015june
global controls_walk="Dpopulation_3 Duniversity_3 Dhospital_pri_3 Dhospital_pub_3 Dodr_3 Dydr_3 medrayic09"
global controls_walk3="akp_pc_2009_belmeclis time_walk_min_2009_belmeclis Dpopulation_3 Duniversity_3 Dhospital_pri_3 Dhospital_pub_3 Dodr_3 Dydr_3 medrayic09"

reg Dakpmargin_3 Dwalk_3 $controls_walk  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table3.tex", keep(Dwalk_3) bdec(3) nocons label tex(frag) replace ///
	addtext(Covariates, YES, Elec2009, MC) nonotes
	
*elec_combo=5: 2009ilgenel,2011,2014belmeclis,2015june
global controls_walk="Dpopulation_5 Duniversity_5 Dhospital_pri_5 Dhospital_pub_5 Dodr_5 Dydr_5 medrayic09"
global controls_walk3="akp_pc_2009_ilgenel time_walk_min_2009_ilgenel Dpopulation_5 Duniversity_5 Dhospital_pri_5 Dhospital_pub_5 Dodr_5 Dydr_5 medrayic09"

reg Dakpmargin_5 Dwalk_5 $controls_walk  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table3.tex", keep(Dwalk_5) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Elec2009, PC) nonotes
		
*elec_combo=3: 2009belmeclis,2011,2014belmeclis,2015june
global controls_walk="Dpopulation_3 Duniversity_3 Dhospital_pri_3 Dhospital_pub_3 Dodr_3 Dydr_3 medrayic09"
global controls_walk3="akp_pc_2009_belmeclis time_walk_min_2009_belmeclis Dpopulation_3 Duniversity_3 Dhospital_pri_3 Dhospital_pub_3 Dodr_3 Dydr_3 medrayic09"
	
reg Dturnout_3 Dwalk_3 $controls_walk  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table3.tex", keep(Dwalk_3) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Elec2009, MC) nonotes

*elec_combo=5: 2009ilgenel,2011,2014belmeclis,2015june
global controls_walk="Dpopulation_5 Duniversity_5 Dhospital_pri_5 Dhospital_pub_5 Dodr_5 Dydr_5 medrayic09"
global controls_walk3="akp_pc_2009_ilgenel time_walk_min_2009_ilgenel Dpopulation_5 Duniversity_5 Dhospital_pri_5 Dhospital_pub_5 Dodr_5 Dydr_5 medrayic09"

reg Dturnout_5 Dwalk_5 $controls_walk  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table3.tex", keep(Dwalk_5) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Elec2009, PC) nonotes


******

* Table 4: produced in Rscript


******
	

* Table 5. Congestion

*elec_combo=3: 2009belmeclis,2011,2014belmeclis,2015june
global controls_doktor="Dwalk_3 Dpopulation_3 Duniversity_3 Dhospital_pri_3 Dhospital_pub_3 Dodr_3 Dydr_3 medrayic09"
global controls_doktor3="akp_pc_2009_belmeclis Dwalk_3 Dpopulation_3 Duniversity_3 Dhospital_pri_3 Dhospital_pub_3 Dodr_3 Dydr_3 medrayic09"

reg Dakp_3 Dpop1000_asm_dr_3 $controls_doktor  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table5.tex", keep(Dpop1000_asm_dr_3) bdec(3) nocons label tex(frag) replace ///
	addtext(Covariates, YES, Baseline Controls, NO, Elec2009, MC) nonotes 	

reg Dakp_3 Dpop1000_asm_dr_3 $controls_doktor3  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table5.tex", keep(Dpop1000_asm_dr_3) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, YES, Elec2009, MC) nonotes 
	
*elec_combo=5: 2009ilgenel,2011,2014belmeclis,2015june
global controls_doktor="Dwalk_5 Dpopulation_5 Duniversity_5 Dhospital_pri_5 Dhospital_pub_5 Dodr_5 Dydr_5 medrayic09"
global controls_doktor3="akp_pc_2009_ilgenel Dwalk_5 Dpopulation_5 Duniversity_5 Dhospital_pri_5 Dhospital_pub_5 Dodr_5 Dydr_5 medrayic09"

reg Dakp_5 Dpop1000_asm_dr_5 $controls_doktor  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table5.tex", keep(Dpop1000_asm_dr_5) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, NO, Elec2009, PC) nonotes 	

reg Dakp_5 Dpop1000_asm_dr_5 $controls_doktor3  if year<2014, cluster(school_id_cluster)
outreg2 using "$output/table5.tex", keep(Dpop1000_asm_dr_5) bdec(3) nocons label tex(frag) append ///
	addtext(Covariates, YES, Baseline Controls, YES, Elec2009, PC) nonotes 

******

	
log close 	
	
	
	
	
	
	

